Passed
Push — 1 ( f8e5cb...ba63b3 )
by Robbie
03:44
created

CampaignActions-test.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 52
rs 9.4929
c 1
b 0
f 0
cc 1
nc 1
nop 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A CampaignActions-test.js ➔ ... ➔ ??? 0 47 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/* global jest, jasmine, describe, it, expect, beforeEach */
2
3
import * as actions from '../CampaignActions';
4
import ACTION_TYPES from '../CampaignActionTypes';
5
import configureMockStore from 'redux-mock-store';
6
import thunk from 'redux-thunk';
7
8
9
describe('CampaignActions', () => {
10
  const middlewares = [thunk];
11
  const mockStore = configureMockStore(middlewares);
12
13
  describe('removeCampaignItems()', () => {
14
    it('should create 2 actions, request and success, when resolved', () => {
15
      const store = mockStore({});
16
      const removeItemApi = () => Promise.resolve();
17
      const expectedActions = [
18
        {
19
          type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_REQUEST,
20
          payload: { campaignId: 1, itemId: 2 },
21
        },
22
        {
23
          type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_SUCCESS,
24
          payload: { campaignId: 1, itemId: 2 },
25
        },
26
      ];
27
28
      return store.dispatch(
29
        actions.removeCampaignItem(removeItemApi, 1, 2)
30
      ).then(() => {
31
        // return of async actions
32
        expect(store.getActions()).toEqual(expectedActions);
33
      });
34
    });
35
36
    it('should create 2 actions, request and failure, when rejected', () => {
37
      const store = mockStore({});
38
      const removeItemApi = () => new Promise((resolve, reject) => {
39
        reject(null);
40
      });
41
      const expectedActions = [
42
        {
43
          type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_REQUEST,
44
          payload: { campaignId: 1, itemId: 2 },
45
        },
46
        {
47
          type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_FAILURE,
48
          payload: { error: null },
49
        },
50
      ];
51
52
      return store.dispatch(
53
        actions.removeCampaignItem(removeItemApi, 1, 2)
54
      ).then(() => {
55
        // return of async actions
56
        expect(store.getActions()).toEqual(expectedActions);
57
      });
58
    });
59
  });
60
});
61